package sapling.timing;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import sapling.dao.MarkorderDao;
import sapling.dao.TreeDao;
import sapling.model.Markorder;
import sapling.model.Tree;
import sapling.utils.Msg;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;


@Component
public class DeblockingTiming {

    @Autowired
    private MarkorderDao markorderDao;
    @Autowired
    private TreeDao treeDao;

    @Scheduled(cron = "0 0 0 * * ?")//每天晚上0点触发一次
    private void process() {
        Date newDate = new Date();
        SimpleDateFormat ymd = new SimpleDateFormat("yyyy-MM-dd");
        String date = ymd.format(newDate);
        List<Markorder> markorders = markorderDao.findHaodate(3,date);
        for (Markorder value:markorders) {
            for (Tree tree:value.getTreesList()) {
                tree.setSalesState(Tree.TYPE_TREE_AWAIT_SELL);
                treeDao.save(tree);
            }
            value.setSalestate(Tree.TYPE_TREE_AWAIT_SELL);
            markorderDao.save(value);
        }
    }

}